package com.kjtpay.design_pattern.composite;

import java.util.ArrayList;

/**
 * 具体公司类；实现接口；数枝节点
 */
class ConcreteCompany extends Company {
    private ArrayList<Company> children = new ArrayList<Company>();

    public ConcreteCompany(String name) {
        super(name);
    }

    @Override
    public void add(Company company) {
        children.add(company);
    }

    @Override
    public void remove(Company company) {
        children.remove(company);
    }

    @Override
    public String display(int depth) {
        String message = new String();
        for (int i = 0; i < depth; i++) {
            message += "-";
        }
        message += name;
        message += "\n";

        for (Company company:
        children) {
            message += company.display(depth + 2);
        }
        return message;
    }

    @Override
    public String lineOfDuty() {
        String message = new String();
        for (Company company:
             children) {
            message += company.lineOfDuty();
        }
        return message;
    }
}
